/*
 * @Author: szx
 * @Date: 2021-12-04 11:08:45
 * @LastEditTime: 2021-12-04 11:13:18
 * @Description:
 * @FilePath: \leetcode\200-299\203\203.js
 */
function ListNode(val, next) {
    this.val = val === undefined ? 0 : val;
    this.next = next === undefined ? null : next;
}
/**
 * Definition for singly-linked list.
 * function ListNode(val, next) {
 *     this.val = (val===undefined ? 0 : val)
 *     this.next = (next===undefined ? null : next)
 * }
 */
/**
 * @param {ListNode} head
 * @param {number} val
 * @return {ListNode}
 */
var removeElements = function (head, val) {
    const prev = new ListNode(-1, head);
    let cur = prev;
    while (cur != null && cur.next != null) {
        if (cur.next.val == val) {
            cur.next = cur.next.next;
        } else {
            cur = cur.next;
        }
    }
    return prev.next;
};
